﻿if exists (select * from dbo.sysobjects where name = 'sp_tblOrder_GetByTop')
	drop procedure [dbo].[sp_tblOrder_GetByTop]
Go 
CREATE PROCEDURE dbo.sp_tblOrder_GetByTop
@Top nvarchar(10),
@Where nvarchar(500), 
@Order nvarchar(500)
AS
	Declare @SQL as nvarchar(500) 
Select @SQL = 'SELECT top (' + @Top + ') * FROM [tblOrder]'
if len(@Top) = 0
BEGIN
Select @SQL = 'SELECT * FROM [tblOrder]'
END
if len(@Where) >0
BEGIN
Select @SQL = @SQL + ' Where ' + @Where
END
if len(@Order) >0
BEGIN
Select @SQL = @SQL + ' Order by ' + @Order
END
EXEC (@SQL)
Go